package com.luoxc.controller;

import com.luoxc.pojo.Result;
import com.luoxc.utils.OssUploadFile;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@Slf4j
@RestController
public class UploadController {
    @Autowired
    private OssUploadFile ossUploadFile;
    // 上传图片
    @PostMapping("/upload")
    private Result upload(MultipartFile image) throws Exception {
        // 存储在本地
//        int index = Objects.requireNonNull(image.getOriginalFilename()).lastIndexOf(".");
//        String filename = image.getOriginalFilename().substring(index);
//        String uuid = UUID.randomUUID().toString();
//        image.transferTo(new File("E:\\java本地存储测试\\" + uuid + filename));
        // 存储在oss
        String url = ossUploadFile.uploadFile(image);
        return Result.success(url);
    }
}
